import moment  from 'moment'
export default{
    install(Vue){
        Vue.mixin({
            data() {
                return {
                    globalPickerOptions: {
                        shortcuts: [{
                            text: '今天',
                            onClick(picker) {
                                picker.$emit('pick', new Date());
                            }
                        }, {
                            text: '昨天',
                            onClick(picker) {
                                const date = new Date();
                                date.setTime(date.getTime() - 3600 * 1000 * 24);
                                picker.$emit('pick', date);
                            }
                        }, {
                            text: '一周前',
                            onClick(picker) {
                                console.log("1");
                                const date = new Date();
                                date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
                                picker.$emit('birth-day-pick', date);
                            }
                        }]
                    },
                }
            },
            methods: {
                funDownload(content, filename) {
                    let eleLink = document.createElement('a')
                    eleLink.download = filename
                    eleLink.style.display = 'none'
                    let blob
                    if (filename.lastIndexOf('.xml') > -1 || filename.lastIndexOf('.txt') > -1) {
                        let Base64 = require('js-base64').Base64
                        blob = new Blob([Base64.decode(content)], { type: 'image/png' })
                    } else {
                        //blob = new Blob([content],{type:'application/pdf'});
                        var binaryString = window.atob(content)
                        var len = binaryString.length
                        var bytes = new Uint8Array(len)
                        for (var i = 0; i < len; i++) {
                            bytes[i] = binaryString.charCodeAt(i)
                        }
                        blob = new Blob([bytes.buffer])
                    }
                    let href = URL.createObjectURL(blob)
                    eleLink.href = href
                    document.body.appendChild(eleLink)
                    eleLink.click()
                    document.body.removeChild(eleLink)
                    window.URL.revokeObjectURL(href)
                },
                _buillStaticPath(path){
                    console.log(path)
                    return window.urlConfig.baseURL+path
                },
                _formatTime(time){
                    return moment(time).format('YYYY-MM-DD HH:mm:ss')
                },
                _formatTime2(time){
                    return moment(time).format('YYYY-MM-DD')
                },
                _formatSex(sex){
                    return sex == 0?'男':'女'
                },
                _formatEquipmentType(value){
                    if(value==0){
                        return "RFID"
                    }else if(value==1){
                        return "充电设备"
                    }else if(value ==2){
                        return "摄像头"
                    }else{
                        return "其它"
                    }
                }
            }
        })
    }
}